﻿@{
    Layout = null;
}

<script src="~/Content/scripts/Common/common.js"></script>
<script type="text/javascript">
    var AssignCombo = {};
    var comboId;
    var action;
    var schoolcode;
    $(function () {
        action = $(top.document).find("#hidAction").val();        
        comboId = $(top.document).find("#hidId").val();
        schoolcode = $(top.document).find("#SchoolCode").val();
        com.ajax({
            url: "/BD/ComboPick/GetComboPerTree?action=" + action,
            type: "Post",
            data: { Id: comboId, schoolcode: schoolcode },
            success: function (data) {
                LoadTree(data);

            }

        })
    });
    function LoadTree(r) {

        if (typeof (r) != "object") {

            r = JSON.parse(r);
        }


        // console.log(r);
        for (var i = 0; i < r.length; i++) {
            $("<div class='fitAssignPer'><ul id='tt" + i + "' ></ul></div>").appendTo(("#divUl"));
            var arr = [r[i]];
            $('#tt' + i).tree({
                data: arr,
                checkbox: true,
                lines: true,
                cascadeCheck: false,
                onlyLeafCheck: true
            });
        }

    }
    AssignCombo.Cancel = function () {
        $("#assignComboPeo").dialog('close');
    }
    AssignCombo.Confirm = function () {
        var nodeIds = "";
        //1.获取所有的树
        var $trees = $(".fitAssignPer > ul");
        //2.遍历所有数
        for (var i = 0; i < $trees.length; i++) {
            var nodes = $($trees[i]).tree("getChecked");
            var nodes2 = $($trees[i]).tree("getChecked", "indeterminate");
            nodes = nodes.concat(nodes2);
            for (var j = 0; j < nodes.length; j++) {
                nodeIds += nodes[j].id + ",";
            }
        }
        com.ajax({
            url: "/BD/ComboPick/EditComboPeoTree?action=" + action,
            data: { Id: comboId, SubCombo: nodeIds },
            success: function (data) {
                com.message(data.state, data.msg, function () {
                    $("#assignComboPeo").dialog('close');
                    if (action == "low") {
                        top.wrapper.tabRefreshByTitle("审批人员配置");
                    }
                    else if (action == "high") {
                        //top.wrapper.tabRefreshByTitle("");
                    }
                    else if (action == "SchoolHead")
                    {
                        top.wrapper.tabRefreshByTitle("校区信息管理");
                    }
                })
            }
        });
    }
</script>

<div id="divUl" style="height: 220px; width: 100%; overflow: auto">
</div>
<div class="dialog-bottom">
    <input type="hidden" id="hidAddRole.Action" />
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="AssignCombo.Confirm()">确定</a>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="AssignCombo.Cancel()">取消</a>
</div>


